//app.js
import { getPzobj, getSessionId, memberInformation } from './api/index'

App({
  onLaunch: function () {
    var that = this
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    getPzobj({
      param: {
        appId: wx.getAccountInfoSync().miniProgram.appId
      }
    }).then(res => {
      if(res.record.shopId) {
        that.globalData.SHOPID = res.record.shopId 
      }
      that.globalData.login = '1314'
    })
    wx.getSystemInfo({
      success: res => {
        //导航高度
        let statusBarHeight = res.statusBarHeight,
        navTop = menuButtonObject.top,
        navObjWid = res.windowWidth - menuButtonObject.right + menuButtonObject.width, // 胶囊按钮与右侧的距离 = windowWidth - right+胶囊宽度
        navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2;
        this.globalData.navHeight = navHeight; //导航栏总体高度
        this.globalData.navTop = navTop; //胶囊距离顶部距离
        this.globalData.navObj = menuButtonObject.height; //胶囊高度
        this.globalData.navObjWid = navObjWid; //胶囊宽度(包括右边距离)
      },
      fail(err) {
        console.log(err);
      }
    })
  },
  // 获取会员信息
  memberInformation() {
    memberInformation({
      param: {
        userId: wx.getStorageSync('userId')
      }
    }).then(res => {
      if (res.errorCode != '000000') return
      wx.setStorageSync('userId', res.record.userId)
      wx.setStorageSync('nickName', res.record.userName)
    })
  },
  onShow: function() {
   
  },
  globalData: {
    SHOPID: '1',
    login: '',
    navHeight: "",
    navTop: "",
    navObj: "",
    navObjWid: ""
  }
})